package com.example.jbmsuppliers.sinopec.utlis;

import android.content.Context;

import com.jbm.jbmsupplier.util.IEGuardKey;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

/**
 * Created by 家帮忙 on 2017/1/23.
 */

public class SaveOpenKeyManage {
    Context context;



    public SaveOpenKeyManage(Context context) {
        this.context = context;
    }

    /**
     * 保存用户的开门key
     */
    private FileOutputStream opfile;
    private ObjectOutputStream obfile;
    public void setsaveOpenkey(ArrayList<IEGuardKey> ArrayListIEKey){
        try {
            opfile = context.openFileOutput("openkey.txt", 0);
             obfile=new ObjectOutputStream(opfile);
            obfile.writeObject(ArrayListIEKey);
            obfile.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (obfile!=null){
                try {
                    obfile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

    }
/**
 * 获取用户的key
 */
    private FileInputStream infile;
    private ObjectInputStream obinfile;
    private ArrayList<IEGuardKey> arrIEguar;
public ArrayList<IEGuardKey> setgainOpenKey(){
    try {
        infile=context.openFileInput("openkey.txt");
        obinfile=new ObjectInputStream(infile);
        if (obinfile!=null)
            arrIEguar=(ArrayList<IEGuardKey>) obinfile.readObject();
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        try {
            if (obinfile!=null)
             obinfile.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
return arrIEguar;

}

}
